<?php

function getPage($query){
	global $posts_per_page, $paged;
	$my_query = new WP_Query($query_string ."&posts_per_page=-1");	
	$total_posts = $my_query->post_count;
	$pageCount = ceil($total_posts/$posts_per_page);
	if($pageCount>1){
		echo '<div id="pageZone">';
		if(empty($paged)){
			$pageIndex = 1;
		}else{
			$pageIndex = $paged;
		}
		
		if($pageIndex>1){
			$prev = get_pagenum_link($pageIndex-1);
			echo "<span class='disabled'><a href='{$prev}'>&lt;&lt;上一页</a></span>";
		}
		
		$start = 1;
		$end = $pageCount;	
		if($pageIndex<=2){
			$start = 1;
			$end = min(5,$pageCount);
		}elseif ($pageIndex>$pageCount-2){
			$start = max($pageCount-4,1);
			$end = $pageCount;
		}else{
			$start = max($pageIndex-2,1);
			$end = min($pageIndex+2,$pageCount);
		}
		
		for($i=$start; $i <= $end; $i++){
			if($i==$pageIndex){
				echo "<span class='isNow'>{$i}</span>";
			}else{
			    $curr = get_pagenum_link($i);
				echo "<span><a href='{$curr}'>{$i}</a></span>";
			}
		}
		
		if($pageIndex<$pageCount){
			$next = get_pagenum_link($pageIndex+1);
			echo "<span class='disabled'><a href='{$next}'>下一页&gt;&gt;</a></span>";
		}
		
		echo '</div>';
	}
	
	/*$prev = $paged - 1;
	$next = $paged + 1;
	$range = 6; // 修改数字,可以显示更多的分页链接
	$showitems = ($range * 2)+1;
	$pages = ceil($total_posts/$posts_per_page);
	
	
	
	
	if(1 != $pages){
		<a href="#">&lt;&lt;上一页</a>
		 <span><a href="#">1</a></span>
		 <span class="isNow">2</span>
		 <span><a href="#">3</a></span>
		 <span><a href="#">4</a></span>
		 <span class="dot">...</span>
		 <span><a href="#">20</a></span>
		 <span class="disabled"><a href="#">下一页&gt;&gt;</a></span>
		print_r($paged);
		echo "<br/>";
		print_r($pages);
		echo "<br/>";
		print_r($showitems);
		echo "<div id='pageZone'>";
		echo ($paged > 2 && $paged+$range+1 > $pages && $showitems < $pages)? "<span class='disabled'><a href='".get_pagenum_link(1)."'>最前</a></span>":"";
		echo ($paged > 1 && $showitems < $pages)? "<span><a href='".get_pagenum_link($prev)."'>&lt;&lt;上一页</a><span>":"";
		for ($i=1; $i <= $pages; $i++){
			if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems )){
				echo ($paged == $i)? "<span class='isNow'>".$i."</span>":"<span><a href='".get_pagenum_link($i)."' class='inactive' >".$i."</a></span>";
			}
		}
		echo ($paged < $pages && $showitems < $pages) ? "<span><a href='".get_pagenum_link($next)."'>下一页&gt;&gt;</a></span>" :"";
		echo ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) ? "<span class='disabled'><a href='".get_pagenum_link($pages)."'>最后</a></span>":"";
		echo "</div>\n";
	}*/

}
?>